package br.com.srv.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateHelper {
	
	public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
	
	public static final String DEFAULT_HOUR_PATTERN = "HH:mm:ss";
	
	public static final String PATTERN_FROM_MODULE = "ddMMyy HHmmss";
	
	/**
	 * Retorna uma String no formato de data pela <code>pattern</code><br>
	 * Exemplo: DateHelper.parseString("dd/MM/yyyy", date)
	 * 
	 * @param pattern
	 *            String
	 * @param value
	 *            String
	 * @return Date
	 * @throws ParseException
	 */
	public static String parseString(String pattern, Date value) {
		SimpleDateFormat formatter = new SimpleDateFormat(pattern);
		return (value != null) ? formatter.format(value) : "";
	}
	
	/**
	 * Retorna uma String no formato de data pela <code>pattern</code><br>
	 * Exemplo: DateHelper.parseString("dd/MM/yyyy", date)
	 * 
	 * @param value
	 *            String
	 * @return Date
	 * @throws ParseException
	 */
	public static String parseString(Date value) {

		return parseString(DEFAULT_DATE_PATTERN + " " + DEFAULT_HOUR_PATTERN, value);
	}	
	
	public static Date parseDate(String pattern, String value) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat(pattern);		
		return format.parse(value);
	}

}
